<template>
  <div class="container">
    <h2 class="handle-title">销售团队管理 > 销售团队</h2>
    <div class="handle-box">
      <div>
        <span class="search-label" style="margin-left: 5px">用户名:</span>
        <el-input v-model="usertruename" style="width: 120px" placeholder="请输入用户名字"></el-input>
        <span class="search-label" style="margin-left: 5px">部门名称:</span>
        <el-select v-model="deptname" style="width: 120px" placeholder="请选择">
          <el-option
            v-for="item in deptnameList"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <span class="search-label" style="margin-left: 5px">审核状态:</span>
        <el-select v-model="value" style="width: 120px">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <el-button class="add_btn" type="primary" @click="addRole">查找</el-button>
      </div>
    </div>
    <el-table
      :data="tableData"
      class="table"
      border>
      <el-table-column prop="deptname" label="机构名称"/>
      <el-table-column prop="showpic" label="头像">
        <template #default="{row}">
          <img :src="row.showpic" alt="" style="width: 50px;height: 50px" >
        </template>
      </el-table-column>
      <el-table-column prop="usertruename" label="用户姓名"/>
      <el-table-column prop="nickname" label="微信昵称"/>
      <el-table-column prop="salercode" label="推荐码"/>
      <el-table-column prop="salerbankname" label="开户行"/>
      <el-table-column prop="salerbanknum" label="银行账户"/>
      <el-table-column prop="salertakepoint" label="提成比例"/>
      <el-table-column label="审核状态">
        <template #default="{row}">
          {{ row.salerauditstate == 1 ? "通过" : "审核中" }}
        </template>
      </el-table-column>

      <el-table-column label="操作" width="200">
        <template #default="{row}">
          <el-button type="text" icon="el-icon-edit-outline" @click="goSearch(row.roleid)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 50]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next"
        :total="totalNum">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {getSalerList} from "../../api/public/api";

export default {
  name: "saler",
  data() {
    return {
      options: [
        {
          value: '-1',
          label: '全部'
        },
        {
          value: '1',
          label: '可用'
        },
        {
          value: '0',
          label: '不可用'
        }
      ],
      deptname: "",
      showpic: "",
      usertruename: '',
      nickname: "",
      salercode: '',
      salerbankname: '',
      salerbanknum: '',
      salertakepoint: '',
      salerauditstate: '',
      tableData: [],   //默认数据列表
      currentPage: 1, //默认第一页
      pageSize: 10,   //默认每页10条
      totalNum: 0,    //默认总条数
    }
  },
  mounted() {
    this.salerList()
  },
  methods: {
    //每页条数
    handleSizeChange(val) {
      this.pageSize = val;
      this.salerList()
    },
    // 第几页
    handleCurrentChange(val) {
      this.currentPage = val;
      this.salerList()
    },
    //封装请求方法
    salerList() {
      let params = {
        pagenum: this.currentPage,
        pagesize: this.pageSize,
        usertruename: this.usertruename,
        deptname: this.deptname,
        showpic: this.showpic,
        nickname: this.nickname,
        salercode: this.salercode,
        salerbankname: this.salerbankname,
        salerbanknum: this.salerbanknum,
        salertakepoint: this.salertakepoint,
        salerauditstate: this.salerauditstate,
      };
      getSalerList(params).then((res) => {
        this.tableData = res.data.pagedata.records;
        this.totalNum = res.data.pagedata.total;
      })
    },
    //Search搜索按钮
    goSearch() {
      this.salerList()
    },
    //新增角色
    addRole() {
      this.$router.push({
        path: "/demo",
        query: {}
      })
    },
    //修改
    goUpdate(id) {
      // console.log(id)
      this.$router.push({
        path: "/updaterole",
        query: {id}
      })
    },
    //权限管理
    goRight(id) {
      this.$router.push({
        path: "/right",
        query: {id}
      })
    },
    goOrder(id) {

    }
  },
}
</script>

<style>
.handle-title {
  line-height: 50px;
}
</style>

